//
//  MCReceivedHBDetailHeaderView.m
//  XDYL
//
//  Created by MC on 2018/3/20.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCReceivedHBDetailHeaderView.h"
//#222222 34,34,34


@interface MCReceivedHBDetailHeaderView()

@property (nonatomic ,strong)UIImageView * logoImgV;
@property (nonatomic ,strong)UILabel * lab1 ;//张学友
@property (nonatomic ,strong)UILabel * lab2 ;//恭喜发财，大吉大利！（红包名称）
@property (nonatomic ,strong)UILabel * lab3 ;//我抢到642.56元
@property (nonatomic ,strong)UILabel * lab4 ;//共十个红包，已抢10/10。

@end

@implementation MCReceivedHBDetailHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    self.backgroundColor=[UIColor whiteColor];
    
    _logoImgV=[[UIImageView alloc]init];
    _logoImgV.image = [UIImage imageNamed:@"shoubao"];
    [self addSubview:_logoImgV];
    [_logoImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(self.mas_top).offset(25);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
    
    /*
     * name
     */
    _lab1=[[UILabel alloc]init];
    _lab1.text=@"加载中...";
    _lab1.font=[UIFont systemFontOfSize:12];
    _lab1.textColor=RGB(34,34,34);
    _lab1.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_lab1];
    [_lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(_logoImgV.mas_bottom).offset(7);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(15);
    }];
    
    /*
     * 恭喜发财，大吉大利！（红包名称）
     */
    
    _lab2=[[UILabel alloc]init];
    _lab2.text=@"加载中...";
    _lab2.font=[UIFont systemFontOfSize:12];
    _lab2.textColor=RGB(161,161,161);
    _lab2.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_lab2];
    [_lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(_logoImgV.mas_bottom).offset(30);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(20);
    }];
    
    
    /*
     *
     */
    _lab3=[[UILabel alloc]initWithFrame:CGRectMake(30, 65+25+15, 150, 15)];
    _lab3.text=@"加载中...";
    _lab3.font=[UIFont systemFontOfSize:12];
    _lab3.textColor=RGB(34,34,34);
    _lab3.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_lab3];
    [_lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(_logoImgV.mas_bottom).offset(55);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(30);
    }];
    
    
    
    _lab4=[[UILabel alloc]initWithFrame:CGRectMake(30, 65+25+15, 150, 15)];
    _lab4.text=@"加载中...";
    _lab4.font=[UIFont systemFontOfSize:12];
    _lab4.textColor=RGB(161,161,161);
    _lab4.textAlignment=NSTextAlignmentLeft;
    [self addSubview:_lab4];
    [_lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(23);
        make.bottom.equalTo(self.mas_bottom).offset(-6);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(15);
    }];
    
    /*
     * 下划线
     */
    UIView * line =[[UIView alloc]init];
    line.backgroundColor=RGB(213,213,213);
    [self  addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-23);
        make.left.equalTo(self.mas_left).offset(23);
        make.bottom.equalTo(self.mas_bottom).offset(-1);
        make.height.mas_equalTo(0.5);
        
    }];
    
    
    
}


+(CGFloat)computeHeight:(id)info{
    return 257;
}


-(void)setDataSource:(MCDetailTotalModel *)dataSource{
    _dataSource = dataSource;

    
    _lab1.text=[NSString stringWithFormat:@"%@",dataSource.UserName];
    _lab2.text=[NSString stringWithFormat:@"%@",dataSource.Name];
    _lab4.text=[NSString stringWithFormat:@"共%@个红包，已抢%@/%@",dataSource.Qty,dataSource.ReceivedNum,dataSource.Qty];
    
    double DGrabAmount = [dataSource.GrabAmount  doubleValue];
    NSString * GrabAmount = [MCMathUnits stringWithDecimalNumber:DGrabAmount];
    
   
    NSString * str = [NSString stringWithFormat:@"我抢到%@元",GrabAmount];
    NSRange range = [str rangeOfString:GrabAmount];
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:str];
    // 修改富文本中的不同文字的样式
    [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(range.location, range.length)];
    // 设置数字为红色
    [attri addAttribute:NSForegroundColorAttributeName value:RGB(255,69,69) range:NSMakeRange(range.location, range.length)];
    
    _lab3.attributedText=attri;
    
    
    if (dataSource.HeadPortrait.length<1) {
        _logoImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"MoRenPerson_1"]];
    }else{
        _logoImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"MoRenPerson_%@",dataSource.HeadPortrait]];
    }

    
}


@end














































